<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="shortcut icon" href="../images/yc.png" type="image/x-icon">
<link rel="stylesheet" href="../css/layui.css" media="all">
</head>
<body>
	<br />
	<form class="layui-form" action="" style="width: 90%">
		<div class="layui-form-item">
			<label class="layui-form-label">原密码</label>
			<div class="layui-input-inline" style="width: 50%">
				<input type="password" name="password" lay-verify="pass"
					placeholder="请输入旧密码" autocomplete="off" class="layui-input" id="oldPwd">
			</div>
			<div class="layui-form-mid layui-word-aux">请填写6到16位密码</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">新密码</label>
			<div class="layui-input-inline" style="width: 50%">
				<input type="password" name="password" lay-verify="pass"
					placeholder="请输入新密码" autocomplete="off" class="layui-input"
					id="newPwd">
			</div>
			<div class="layui-form-mid layui-word-aux">请填写6到16位新密码</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">确认密码</label>
			<div class="layui-input-inline" style="width: 50%">
				<input type="password" name="password" lay-verify="pass"
					placeholder="请再次输入新密码" autocomplete="off" class="layui-input"
					id="rePwd">
			</div>
			<div class="layui-form-mid layui-word-aux">请再次填写6到16位的新密码</div>
		</div>

		<div class="layui-form-item">
			<div class="layui-input-block">
				<button type="submit" class="layui-btn" lay-submit=""
					lay-filter="demo1">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</div>
	</form>

	<script src="../../js/jquery-3.4.1.min.js" charset="utf-8"></script>
	<script src="../../js/show-dialog.js" charset="utf-8"></script>
	<script type="text/javascript" src="../js/layui.all.js" charset="utf-8"></script>
	<script>
layui.use(['form', 'layedit', 'laydate'], function(){
	var form = layui.form,
	layer = layui.layer,
	layedit = layui.layedit,
	laydate = layui.laydate;
	
	// 自定义验证规则
	form.verify({
		pass: [/^[\S]{6,12}$/, '密码必须6到16位，且不能出现空格...']
	});
	
	
  
	// 监听提交
  	form.on('submit(demo1)', function(data){
  		let pwd = $("#newPwd").val();
  		let rePwd = $("#rePwd").val();
  		let oldPwd = $("#oldPwd").val();
  		if(pwd != rePwd){
  			layer.alert(JSON.stringify(), {
  	      		title: '两次输入密码不一致!'
  	    	})
  	    	
  		}else if(oldPwd == rePwd){
  	  		
  		    layer.alert(JSON.stringify(), {
  	      		title: '原密码不能跟新密码一致!'
  	    	})
  	  	}else{
  	  		$.post("/admin/update",{pwd:pwd,oldPwd:oldPwd},rt=>{
  	  			console.log(rt)
  	  			if(rt.code == 522){
  	  				showmsg("请输入正确密码","yellow");
  	  				return;
  	  			}else if(rt.code == 500){
  	  			    showmsg("修改失败,请稍后再试","red");
	  				return;
  	  			}else{
  	  			    showmsg("修改成功...正在跳转到登陆界面","green",function(){
  	  	  		    window.parent.location.href="/admin/loginout";
  	  	  		})
  	  			}
  	  		},"json");
  	  		
	  		}
		return false;
	});
});
</script>
</body>
</html>